package com.horizon.wxapp.controller;

import com.horizon.wxapp.entity.Carts;
import com.horizon.wxapp.service.CartsService;
import com.horizon.wxapp.vo.UserCarts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("carts")
public class CartsController {

    @Autowired
    private CartsService cartsService;

    @RequestMapping("update")
    public void update(@RequestBody Carts carts) {
        cartsService.updateCart(carts);
    }

    @RequestMapping("delete/{id}")
    public void delete(@PathVariable Integer id) {
        cartsService.deleteCartById(id);
    }

    @RequestMapping
    public List<UserCarts> select(String userName, String tel) {
        return cartsService.selectCarts(userName, tel);
    }

    @RequestMapping("getCart")
    public Carts selectOne(String userName, String tel, Integer goodId) {
        return cartsService.selectOne(userName, tel, goodId);
    }

    @PostMapping("add")
    public void insert(@RequestBody Carts cart) {
        cartsService.addCart(cart);
    }


}
